/*
 * @Author: DUST
 * @Date: 2023-05-27 17:59:16
 * @LastEditors: DUST
 * @LastEditTime: 2023-07-03 14:49:31
 * @FilePath: \koa-node-ts\app\db\sequelize.ts
 * @Description:
 * undefined
 */
import { Sequelize } from "sequelize-typescript";
import config from "../config";
import path from "path";
import { dbLogger } from "../logger";
import models from "./models";

const sequelize = new Sequelize(
  config.db.db_name as string,
  config.db.db_user as string,
  config.db.db_password as string,
  {
    host: config.db.db_host,
    port: config.db.db_post as unknown as number,
    dialect: "mysql",
    logging: (msg) => dbLogger.info(msg), // 显示所有日志函数调用参数
    pool: {
      max: 10,
      min: 0,
    },
    timezone: "+08:00", //一定要这么设置才能按照北京时间来记录时间相关的数据
    define: {
      timestamps: true,
      createdAt: "createTime",
      updatedAt: "upTime",
      deletedAt: "deleteTime",
    },
    models: [
      ...models
      // path.join(__dirname, "..", (process.env.NODE_ENV == 'build' ? "model/**/*.ts" : "model/**/*.ts")),
      // path.join(__dirname, "..", "model/**/*.ts"),
    ],
  }
);



export default sequelize;
